import Vue from 'vue'
import PC from './PC.vue'
import router from '@/router/pc'
import store from '../../store/index'

import http from '@u/http/index'
import utils from '@u/utils'
import decorator from '@u/decorator'
import chUI from '@c/pc/index'
import '@a/font/index.css'

import '@a/theme#ee3f4d/theme/index.css'
import ElementUI from 'element-ui'
import { Loading } from 'element-ui'

Vue.config.productionTip = false

Vue.use(utils)
Vue.use(http)
Vue.use(decorator)
Vue.use(ElementUI, {size: 'mini'})
Vue.use(chUI)

router.afterEach((to, from) => {
  // 页面加载提示
  let loadingInstance = Loading.service({ fullscreen: true })
  let loading = setInterval(() => {
    if (document.readyState === 'complete') {
      loadingInstance.close()
      window.clearInterval(loading)
    }
  }, 500)

  let bodyScrollTop = document.body.scrollTop
  if (bodyScrollTop !== 0) {
    document.body.scrollTop = 0
    return
  }
  let docScrollTop = document.documentElement.scrollTop
  if (docScrollTop !== 0) {
    document.documentElement.scrollTop = 0
  }
})

// 解决跳转后页面不在最顶端的问题
// router.afterEach((to, from) => {
//   let bodyScrollTop = document.body.scrollTop
//   if (bodyScrollTop !== 0) {
//     document.body.scrollTop = 0
//     return
//   }
//   let docScrollTop = document.documentElement.scrollTop
//   if (docScrollTop !== 0) {
//     document.documentElement.scrollTop = 0
//   }
// })

if (sessionStorage.getItem('tokenInfo')) {
  store.commit('UPDATE_USER_INFO')
}

/* eslint-disable no-new */
new Vue({
  el: '#pc',
  router,
  store,
  render: h => h(PC)
})
